#include <GL/freeglut.h>
#include <Windows.h>

// 获取屏幕分辨率，使用Windows.h提供的函数
int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);

// 初始窗口大小
int windowWidth = 800;
int windowHeight = 600;

void display()
{
    glColor3f(0, 1.0, 0);
    glBegin(GL_TRIANGLES);
    glVertex2f(0.5, 0.5);
    glVertex2f(-0.5, 0.5);
    glVertex2f(0, -0.5);
    glEnd();
    glFlush();
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(windowWidth, windowHeight);
    // 计算窗口左上角坐标，使窗口始终居中，详见解析
    int winPos_x = nScreenWidth / 2 - windowWidth / 2;
    int winPos_y = nScreenHeight / 2 - windowHeight / 2;
    glutInitWindowPosition(winPos_x, winPos_y);
    glutCreateWindow("绘制三角形");
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}
